home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fsio / fsioClientList.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  5KB  |  160 lines

  1. /* 
  2.  * fsClientList.c --
  3.  *
  4.  *    Routines to handle the client lists maintained at the stream level.
  5.  *    The stream-level client list is needed for migration.  It is not to
  6.  *    be confused with the client list that hangs off the I/O handles.
  7.  *
  8.  *
  9.  * Copyright 1987 Regents of the University of California
  10.  * All rights reserved.
  11.  * Permission to use, copy, modify, and distribute this
  12.  * software and its documentation for any purpose and without
  13.  * fee is hereby granted, provided that the above copyright
  14.  * notice appear in all copies.  The University of California
  15.  * makes no representations about the suitability of this
  16.  * software for any purpose.  It is provided "as is" without
  17.  * express or implied warranty.
  18.  */
  19.  
  20. #ifndef lint
  21. static char rcsid[] = "$Header: /sprite/src/kernel/fsio/RCS/fsioClientList.c,v 9.2 90/10/08 15:47:39 mendel Exp $ SPRITE (Berkeley)";
  22. #endif not lint
  23.  
  24.  
  25. #include <sprite.h>
  26. #include <fs.h>
  27. #include <fsutil.h>
  28. #include <fsconsist.h>
  29. #include <fsio.h>
  30. #include <fsStat.h>
  31. #include <rpc.h>
  32.  
  33.  
  34.  
  35. /*
  36.  * ----------------------------------------------------------------------------
  37.  *
  38.  * Fsio_StreamClientOpen --
  39.  *
  40.  *    Add a client to the set of clients for a stream.  When a stream is
  41.  *    created the client list is started, and when migration causes
  42.  *    the stream to be shared by processes on different clients, new client
  43.  *    list elements are added.
  44.  *
  45.  * Results:
  46.  *    TRUE if the stream is shared by different clients after the open.
  47.  *    FALSE if this client is the only client of the stream.
  48.  *
  49.  * Side effects:
  50.  *    As well as putting the client in it's list,
  51.  *    the client is recorded in the master list of clients (if it isn't
  52.  *    already there) so client hosts can be easily scavenged.
  53.  *
  54.  * ----------------------------------------------------------------------------
  55.  */
  56. /*ARGSUSED*/
  57. Boolean
  58. Fsio_StreamClientOpen(clientList, clientID, useFlags, foundPtr)
  59.     List_Links        *clientList;    /* List of clients */
  60.     int            clientID;    /* The client who is opening the file */
  61.     int            useFlags;    /* FS_READ | FS_WRITE | FS_EXECUTE */
  62.     Boolean        *foundPtr;    /* Return - TRUE if client existed */
  63. {
  64.     register FsioStreamClient *clientPtr;
  65.     register Boolean found = FALSE;
  66.     register Boolean shared = FALSE;
  67.  
  68.     LIST_FORALL(clientList, (List_Links *)clientPtr) {
  69.     if (clientPtr->clientID == clientID) {
  70.         found = TRUE;
  71.     } else {
  72.         shared = TRUE;
  73.         if (found) {
  74.         break;
  75.         }
  76.     }
  77.     }
  78.     if (!found) {
  79.     clientPtr = mnew(FsioStreamClient);
  80.     clientPtr->clientID = clientID;
  81.     List_InitElement((List_Links *)clientPtr);
  82.     List_Insert((List_Links *) clientPtr, LIST_ATFRONT(clientList));
  83.     fs_Stats.object.streamClients++;
  84.     }
  85.  
  86.     /*
  87.      * Make sure the client is in the master list of all clients for this host.
  88.      */
  89.     Fsconsist_AddClient(clientID);
  90.     if (foundPtr != (Boolean *)NIL) {
  91.     *foundPtr = found;
  92.     }
  93.     return(shared);
  94. }
  95.  
  96. /*
  97.  * ----------------------------------------------------------------------------
  98.  *
  99.  * Fsio_StreamClientClose --
  100.  *
  101.  *    Remove a client from the client list of a stream.
  102.  *
  103.  * Results:
  104.  *    TRUE if the client list is empty after the close.
  105.  *
  106.  * Side effects:
  107.  *    The client list entry from the stream is removed.
  108.  *
  109.  * ----------------------------------------------------------------------------
  110.  *
  111.  */
  112. Boolean
  113. Fsio_StreamClientClose(clientList, clientID)
  114.     List_Links        *clientList;    /* List of clients who have it open */
  115.     int            clientID;    /* Host ID of client that had it open */
  116. {
  117.     register    FsioStreamClient    *clientPtr;
  118.  
  119.     LIST_FORALL(clientList, (List_Links *) clientPtr) {
  120.     if (clientPtr->clientID == clientID) {
  121.         List_Remove((List_Links *) clientPtr);
  122.         free((Address) clientPtr);
  123.         fs_Stats.object.streamClients--;
  124.         break;
  125.     }
  126.     }
  127.     return(List_IsEmpty(clientList));
  128. }
  129.  
  130. /*
  131.  * ----------------------------------------------------------------------------
  132.  *
  133.  * Fsio_StreamClientFind --
  134.  *
  135.  *      See if a client appears in a client list.
  136.  *
  137.  * Results:
  138.  *      TRUE if the client is in the list.
  139.  *
  140.  * Side effects:
  141.  *      None.
  142.  *
  143.  * ----------------------------------------------------------------------------
  144.  *
  145.  */
  146. Boolean
  147. Fsio_StreamClientFind(clientList, clientID)
  148.     List_Links          *clientList;    /* List of clients who have it open */
  149.     int                 clientID;       /* Host ID of client to find */
  150. {
  151.     register    FsioStreamClient      *clientPtr;
  152.  
  153.     LIST_FORALL(clientList, (List_Links *) clientPtr) {
  154.     if (clientPtr->clientID == clientID) {
  155.         return(TRUE);
  156.     }
  157.     }
  158.     return(FALSE);
  159. }
  160.